<?php
	require_once 'CheckoutManager.php';
	class CheckoutView{
	
	public function searchStudent($param1){
			
			$conn = oci_connect("naiad", "1234", "localhost/XE");
			$a = oci_parse($conn, "select a.STUDENTNO,a.NAMEFIRST, a.NAMEMIDDLE, a.NAMELAST, b.ROOMNO FROM STUDENT a, CHECK_IN b where a.STUDENTNO=b.STUDENTNO AND a.STUDENTNO like '".$param1."'");
			oci_execute($a);
			$nrows = oci_fetch_all($a, $results);
			if($nrows!=0){ return 1;
			}else{ return 0; }
		
	}
	
	function showMessage($flag) {
				if($flag==1){
					$msg = "Check-out successful!";
					$destination = "checkoutForm.php";
				}else{
					$msg = "Error in deletion!";
					$destination = "checkoutForm.php";
				}
			
				echo("<html>\n");
				echo("<head>\n");
				echo("<title>System Message</title>\n");
				echo("<meta http-equiv=\"Content-Type\" content=\"text/html;
				charset=iso-8859-1\">\n");

				echo("<script language=\"JavaScript\" type=\"text/JavaScript\">\n");
				echo("alert('$msg');\n");
				echo("window.location = ('$destination');\n");
				echo("</script>\n");
				echo("</head>\n");
				echo("<body>\n");
				echo("</body>\n");
				echo("</html>\n");
				exit;
			}
			
	public function deleteStudent($snum){	
			$flag1 = CheckoutManager::deleteResident($snum);
			$flag2 = CheckoutManager::updateCheckin($snum);
			$newObj = new CheckoutView;
			if($flag1 == 1 && $flag2==1 ) $flag = 1;
			else $flag = 0;
			$newObj->showMessage($flag);
			
		}
		
	public function updateStudent($snum){		
			$flag2 = CheckoutManager::updateCheckin($snum);
			$newObj = new CheckoutView;
			if($flag2==1 ) $flag = 1;
			else $flag = 0;
			$newObj->showMessage($flag);
			
		}
	}

?>